#include <iostream>  
#include <curl/curl.h>  
  
size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userp) {  
    ((std::string*)userp)->append((char*)contents, size * nmemb);  
    return size * nmemb;  
}  
  
std::string sendHTTPRequest(const std::string& url) {  
    CURL* curl;  
    CURLcode res;  
    std::string readBuffer;  
  
    curl_global_init(CURL_GLOBAL_DEFAULT);  
    curl = curl_easy_init();  
    if(curl) {  
        curl_easy_setopt(curl, CURLOPT_URL, url.c_str());  
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);  
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);  
        res = curl_easy_perform(curl);  
        if(res != CURLE_OK) {  
            std::cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << std::endl;  
        }  
        curl_easy_cleanup(curl);  
    }  
    curl_global_cleanup();  
    return readBuffer;  
}  
  
int main() {  
    std::cout << "Start ..." << std::endl;
    std::string url = "http://www.baidu.com";  
    std::string response = sendHTTPRequest(url);  
    std::cout << response << std::endl;  
    return 0;  
}